package cn.ecut;

import java.sql.*;

public class PreparedState {
    public static void main(String[] args) throws Exception{
        // 加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 获取连接
        String url = "jdbc:mysql://localhost:3306/ecut?serverTimezone=Asia/Shanghai" ;
        String username = "root" ;
        String password = "root" ;
        Connection connection = DriverManager.getConnection(url , username , password ) ;

        String insert_sql = "insert into country( countryname, countrycode) values (?,?) " ;
        String update_sql = "update country set countrycode=? where countryname=?" ;
        String delete_sql = "delete from country where id= ? " ;
        PreparedStatement psinsert = connection.prepareStatement(insert_sql);
        psinsert.setString( 1,"缅甸" );
        psinsert.setString( 2,"md" );
        int i = psinsert.executeUpdate();
        PreparedStatement psupdate = connection.prepareStatement(update_sql);
        psupdate.setString( 1,"mdmd" );
        psupdate.setString( 2,"缅甸" );
        System.out.println( i );
        int i2 = psupdate.executeUpdate();
        System.out.println( i2 );
        PreparedStatement psdelete = connection.prepareStatement(delete_sql);
        psdelete.setInt( 1,3 );
        int i3 = psdelete.executeUpdate();
        System.out.println( i3 );
        psinsert.close();
        connection.close();
    }
}
